package cc.shinichi.library.utils

import android.app.Activity
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.StringRes
import cc.shinichi.library.R
import com.blankj.utilcode.util.ToastUtils

/**
 * 版权：Zhujiang 个人版权
 * @author zhujiang
 * 版本：1.5
 * 创建日期：2020/5/15
 * 描述：PlayAndroid
 *
 */

//fun showToast(msg: String, local: Int = Gravity.CENTER) {
//    if (local == Gravity.CENTER) {
//        ToastUtils.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
//    } else if (local == Gravity.BOTTOM) {
//        ToastUtils.setGravity(Gravity.BOTTOM, 0, 0)
//    } else if (local == Gravity.TOP) {
//        ToastUtils.setGravity(Gravity.TOP, 0, 0)
//    }
//    val view: View =
//        LayoutInflater.from(BaseApplication._context).inflate(R.layout.toast_custom_view, null)
//    view.findViewById<TextView>(R.id.id_content).text = msg
//    ToastUtils.showCustomShort(view)
//}

fun showToast(context: Context, msg: String) {
    val inflater: LayoutInflater = (context as Activity).layoutInflater
    val view: View = inflater.inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = msg
    ToastUtils.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    ToastUtils.showCustomShort(view)
}

fun showYgxToast(context: Context, msg: String) {
    val inflater: LayoutInflater = (context as Activity).layoutInflater
    val view: View = inflater.inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = msg
    val toast = Toast(context)
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    toast.duration = Toast.LENGTH_SHORT
    toast.view = view
    toast.show()
}

//fun showToast(@StringRes msg: Int) {
//    showToast(msg.toString())
////    ToastUtils.showShort(msg)
//}

fun showToast(context: Context, @StringRes msg: Int) {
    val inflater: LayoutInflater = (context as Activity).layoutInflater
    val view: View = inflater.inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = (context as Activity).getString(msg)
    ToastUtils.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    ToastUtils.showCustomShort(view)
}

fun showLongToast(msg: String) {
    ToastUtils.showLong(msg)
}

fun showLongToast(@StringRes msg: Int) {
    ToastUtils.showLong(msg)
}